package com.atguigu.juc.tool;

import java.util.concurrent.CountDownLatch;

public class CountdownLatchTest {

    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(10);

        for (int i = 0; i < 10; i++) {
            int index = i;
            new Thread(()->{
                System.out.println("inner operation " + index);

                // 递减操作，表示完成了一个任务
                countDownLatch.countDown();
            }).start();
        }

        // 抑制最后一步，等前面所有的步骤都完成再执行最后一步
        countDownLatch.await();
        System.out.println("outer operation");
    }

}
